<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1 class="title">子应用</h1>
    <script>
      // 读写二合一
      document.cookie = "token=123456";
      // console.log(document.cookie);
      // 子应用接受消息
      // window.onmessage = function () {}
      window.addEventListener("message", function (e) {
        // 接受父组件的消息（绑定事件）
        console.log(e.data);
      });

      document.querySelector("h1").onclick = function () {
        // window.parent // 父应用的window
        window.parent.postMessage(
          "子应用给父应用发送消息",
          "http://127.0.0.1:5502"
        );
      };
    </script>
  </body>
</html>
